package com.jcgyl.export.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jcgyl.export.dao.PostDao;
import com.jcgyl.export.service.PostRoleService;
import com.jcgyl.export.util.entity.Result;
@Service
public class PostRoleServiceImpl implements PostRoleService {
	@Autowired
	private PostDao postDao;

	@Override
	public List<Integer> findRoleIdByPid(int Pid) {
		List<Integer> list=	postDao.findRoleIdByPid(Pid);
		return list;
	}

	@Override
	public Result updatePermissionsbyRoleId(int pid, List<Integer> list) {
		List<Integer> list_r = postDao.findRoleIdByPid(pid);
		System.out.println(list_r);
		try {
			int rid;
			for (int i = 0; i < list_r.size(); i++) {
				rid=list_r.get(i);
				postDao.deleteRolebyRoleId(rid, pid);
			}
			for (int i = 0; i < list.size(); i++) {
				rid=list.get(i);
				postDao.insertRolebyRoleId(rid, pid);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			return Result.build(1, "根据角色ID修改权限时发生错误");
		}
		return Result.ok("保存成功");
	}

}
